package cn.xiongxf.exception;

/**
 * 为了区别系统异常与业务异常（都要给用户友好提示），我们需要抛出自定义的异常
 */
public class GlobalCustomException extends RuntimeException {
    private String errorMessage;
    private String errorCode;

    public GlobalCustomException(){
        super();
    }
    public GlobalCustomException(String message){
        super(message);
    }

    // 手动输入异常类有参构造
    public GlobalCustomException(String errorMessage,String errorCode){
        // 调RuntimeException中的构造方法，让RuntimeException的message = errorMessage，e.getMessage不为null
        super(errorMessage);
        this.errorMessage = errorMessage;
        this.errorCode = errorCode;
    }

    // 枚举异常类有参构造
    public GlobalCustomException(GlobalErrorCode globalErrorCode){
        super(globalErrorCode.getMessage());
        this.errorMessage = globalErrorCode.getMessage();
        this.errorCode = globalErrorCode.getCode();
    }

    public String getErrorMessage() {
        return errorMessage;
    }
    public String getErrorCode() {
        return errorCode;
    }
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }
}
